package com.ricky02.condition;

import org.springframework.boot.autoconfigure.condition.ConditionalOnJava;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.system.JavaVersion;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

/**
 * 不加@Conditional之前是加载两个字符集
 * 加了之后则只有utf8
 * org.springframework.boot.autoconfigure.condition包下有很多提供好的工具
 */
@Configuration
//也可以写到这个位置进行条件判断 下面实例是两个都为真才加载里面的实例
//@Conditional(GBKConditon.class,UTF8Conditon.class)
public class ConditionConfigBean {

    @Bean
    @Conditional(GBKConditon.class)
    public  GBKConditionConfig createGBK(){
        return new GBKConditionConfig();
    }
    @Bean
    @Conditional(UTF8Conditon.class)
    //jdk是8的时候才执行
//    @ConditionalOnJava(JavaVersion.NINE)
    //配置不存在的时候是true 有的话 根据值判断
    @ConditionalOnProperty(name="name2",havingValue = "ricky2",matchIfMissing = true)
    public  UTF8ConditionConfig createUTF8(){
        return new UTF8ConditionConfig();
    }
}
